﻿procedure;
var 
  dingo_sl : TStringList;
  dingo_ds : TAppDataSet;
  dingo_sSourceBatchID : string;   

  
  SLEx, SLID, SLPpv, SLPar, SL: TStringList;
  DSClass: TAppDataSet;
  PeM_IDKonf, idPpv, idMV, idEmpl, ic, u, ID: String;
  i: integer;
  transRep: boolean;
  
  //MaSu
  MaSu_DS: TAppDataSet;
  MaSu_SL: TStringList; 
  MaSu_i: integer;
  
  MP_SLDochSl: TStringList;
  MP_Index: Integer;
  
  procedure PStu_Set1Global(atrFrom, atrTo: string);
  var rec, hodn: string;
  begin //PŠtu
    rec := GetUserGlobals('', 'ic', '')+','+GetUserGlobals('', 'u', '');
    hodn:= GetUserGlobals('', atrFrom, ''); //dříve společný, nyní: Prodej
    AppServer.SetDBAtrValue(SourceName, MainLang, '15777,10', atrTo, rec, hodn);
  end;
  
  procedure PStu_naprav2720152;
  var
    dsR: TAppDataSet;
    priste: DateTime;
    freq: float;
    ansiNext, platiOd, platiDO: string;
  begin //již nebude ručně možné editovat DPF, pokud existuje vazba z OSOP(152) na položku výdejky - proto doplň datumy DPF
    dsR:= TAppDataSet.Create;
    try
      dsR.SetDSParams(SourceName, rmPrimary, '2449595,9', dsaFullNonVisible);
      dsR.Filter:= '("42163151,10.ic" is not null) and (("2449599,9" is null) or ("2449599,9"<>Convert(date, "42163162,10")))';
      dsR.Open;
      While not dsR.Eof do begin
        dsR.Edit;
        //1) datum DPF
        dsR.FieldByName('2449599,9').AsANSIString:= dsR.FieldByName('42163200,10').AsANSIString;
        //2) datum DPříF 17.7.2025, 1.9.2025
        ansiNext:= '';
        freq:= dsR.FieldByName('2449602,9').AsFloat; //0=jednorazová potřeba
        If (freq<>0) and not dsR.FieldByName('2449599,9').IsNull then begin
          platiOd := dsR.FieldByName('2449597,9').AsANSIString;
          platiDO := dsR.FieldByName('2449598,9').AsANSIString;
          priste  := DateAdd(dpMonth, Trunc(freq), dsR.FieldByName('2449599,9').AsDateTime);
          ansiNext:= DateToANSIStr(priste);
          If not( ((platiOd='') or (platiOd<=ansiNext)) and ((ansiNext<=platiDO) or (platiDO='')) )
          then ansiNext:= '';
        end;
        dsR.FieldByName('42098378,10').AsANSIString:= ansiNext;
        //---
        dsR.PostNoConfirm;
        dsR.Next
      end;
    finally
      dsR.Free
    end;
  end;

  // MP nastavení doch. složek
  procedure VeVolnuSouvNepr(KodDS: String);
  var
   IDDS: String;
  begin
    IDDS := AppServer.GetDBKeyValuesEx(SourceName, rmPrimary, '17830,10218', Format('"17833,10218"=''%%''', [KodDS]), '', [], Legislation, 0, ftID);
    if IDDS <> '' then
      AppServer.SetDBAtrValue(SourceName, '', '17830,10218', '20357932,10', ElemByIndex(IDDS, 0, ';'), '2');
  end;
  // MP end
  
  
  // AV - Vícenásobný propad zboží a rolí
  
  procedure AV1_REINSTALL_ODDELENI_ROLI_A_ZBOZI;

    function AllSubordinateClasses(CLASS_ID: String): String;
    var
      SL: TStringList;
      tmp: String;
    begin
      SL := TStringList.Create;
      try
        Result := AppServer.GetDBKeyValue(SourceName, rmPrimary, '136,0', CLASS_ID, ftIDA, ftIDB);
        StringToSL(Result, ';', SL);
        while SL.Count <> 0 do
        begin
          tmp := AllSubordinateClasses(SL.Strings[0]);
          if tmp <> '' then
            Result := Result + ';' + tmp;
          SL.Delete(0);
        end;
      finally
        SL.Free;
      end;
    end;

    procedure GetBinds(CLASSES_LIST: STRING; VAR VAR_BINDS_A, VAR_BINDS_B: STRING);
      procedure AddStringToList(SL: TStringList; STR: String);
      var SL_TMP: TStringList;
      begin
        if STR <> '' then
        begin
          SL_TMP := TStringList.Create;
          try
            StringToSL(STR, ';', SL_TMP);
            while SL_TMP.Count <> 0 do
            begin
              if SL.IndexOf(SL_TMP.Strings[0]) = -1 then
                SL.Add(SL_TMP.Strings[0]);
              SL_TMP.Delete(0);
            end;
          finally
            SL_TMP.Free;
          end;
        end;
      end;
      
    var SL, SLResultA, SLResultB: TStringList;
    begin
      SL := TStringList.Create;
      SLResultA := TStringList.Create;
      SLResultB := TStringList.Create;
      try
        StringToSL(CLASSES_LIST, ';', SL);
        while SL.Count <> 0 do
        begin
          AddStringToList(SLResultA, AppServer.GetDBKeyValue(SourceName, rmPrimary, '101,0', SL.Strings[0], ftIDA, ftID));
          AddStringToList(SLResultB, AppServer.GetDBKeyValue(SourceName, rmPrimary, '101,0', SL.Strings[0], ftIDB, ftID));
          SL.Delete(0);
        end;
        //
        VAR_BINDS_A := SLToString(SLResultA, ';');
        VAR_BINDS_B := SLToString(SLResultB, ';');
      finally
        SL.Free;
        SLResultA.Free;
        SLResultB.Free;
      end;
    end;

    function AddIfExist(BASE, TO_BE_ADD: String): String;
    var SL: TStringList;
    begin
      SL := TStringList.Create;
      try
        Result := BASE;
        StringToSL(TO_BE_ADD, ';', SL);
        //
        while SL.Count <> 0 do
        begin
          if AppServer.ExistDBKeyValue(SourceName, rmPrimary, '101,0', SL.Strings[0]) then
            Result := Format('%%;%%', [Result, SL.Strings[0]]);
          SL.Delete(0);
        end;
      finally
        SL.Free;
      end;
    end;

    procedure DeleteRecordFromClass(id_record, class_id, bind_a_id, bind_b_id: String);
    var
      SL, SL2: TStringList;
    begin
      SL := TStringList.Create;
      SL2 := TStringList.Create;
      try
        StringToSL(bind_a_id, ';', SL);
        while SL.Count <> 0 do
        begin
          StringToSL(AppServer.GetDBKeyValue(SourceName, rmPrimary, SL.Strings[0], id_record, ftIDA, ftID), ';', SL2);
          while SL2.Count <> 0 do
          begin
            AppServer.DeleteDBRecord(SourceName, SL.Strings[0], SL2.Strings[0], true);
            SL2.Delete(0);
          end;
          SL.Delete(0);
        end;
        //
        StringToSL(bind_b_id, ';', SL);
        while SL.Count <> 0 do
        begin
          StringToSL(AppServer.GetDBKeyValue(SourceName, rmPrimary, SL.Strings[0], id_record, ftIDB, ftID), ';', SL2);
          while SL2.Count <> 0 do
          begin
            AppServer.DeleteDBRecord(SourceName, SL.Strings[0], SL2.Strings[0], true);
            SL2.Delete(0);
          end;
          SL.Delete(0);
        end;
        //
        StringToSL(class_id, ';', SL);
        while SL.Count <> 0 do
        begin
          AppServer.DeleteDBRecord(SourceName, SL.Strings[0], id_record, true);
          SL.Delete(0);
        end;
      finally
        SL.Free;
        SL2.Free;
      end;
    end;

  var
    SLRec, SLBindsGoodsA, SLBindsGoodsB, SLBindsRolesA, SLBindsRolesB, SLProblems: TStringList;
    DS: TAppDataSet;
    //
    i, j, total: Integer;
    break, continue, found: Boolean;
    //
    id, ic, u: String;
    count, nok: Integer;
    //
    classes_goods, classes_roles: String;
    binds_goods_A, binds_goods_B, binds_roles_A, binds_roles_B: String;
    delete_binds_goods_A, delete_binds_goods_B, delete_binds_roles_A, delete_binds_roles_B: String;
    tmp: String;
  begin
    SLRec := TStringList.Create;
    SLBindsGoodsA := TStringList.Create;
    SLBindsGoodsB := TStringList.Create;
    SLBindsRolesA := TStringList.Create;
    SLBindsRolesB := TStringList.Create;
    SLProblems := TStringList.Create;
    DS := TAppDataSet.Create;
    try
      StringToSL(AppServer.GetDBKeyValuesEx(SourceName, rmPrimary, '3009,10', '1=1', '3460,10', [], '', 0.0, ftID), ';', SLRec);
      total := SLRec.Count;
      //
      classes_goods := '3460,10' + ';' + AllSubordinateClasses('3460,10');
      classes_roles := '3009,10' + ';' + AllSubordinateClasses('3009,10');
      GetBinds(classes_goods, binds_goods_A, binds_goods_B);
      GetBinds(classes_roles, binds_roles_A, binds_roles_B);
      //
      delete_binds_goods_A := binds_goods_A;
      delete_binds_goods_B := binds_goods_B;
      delete_binds_roles_A := binds_roles_A;
      delete_binds_roles_B := binds_roles_B;
      //
      binds_goods_A := AddIfExist(binds_goods_A, '124422,9;38239,10;38239,10;227959,10;451692,10;964079,10;1140365,10;2338989,10;7049988,10;19692459,10;38661505,10;1137962,10212;32310,9;9810,10;43370,10;181355,10;227744,10;1613054,10;289501,10;402050,10;432250,10;843892,10;2353569,10;8160570,10;11628533,10;13216832,10;471611,11011;21309380,10;21689181,10;26922895,10;14462677,10;22384805,10;28888959,10;411369,10;1118643,10;877928,10');
      binds_goods_B := AddIfExist(binds_goods_B, '124422,9;3396060,10;4344110,10;4744837,10;6891080,10;12626702,10;18874168,10;308965,10008;9810,10;402190,10;1412908,10;3672290,10;4151503,10;4344104,10;12066751,10;14472339,10;29041044,10;14462677,10;22384805,10;28888959,10;7775,10');
      binds_roles_A := AddIfExist(binds_roles_A, '7493234,10');
      binds_roles_B := AddIfExist(binds_roles_B, '');
      //
      StringToSL(binds_goods_A, ';', SLBindsGoodsA);
      StringToSL(binds_goods_B, ';', SLBindsGoodsB);
      StringToSL(binds_roles_A, ';', SLBindsRolesA);
      StringToSL(binds_roles_B, ';', SLBindsRolesB);
      //
      DS.SetDSParams(SourceName, rmPrimary, '42056531,10', dsaReadNonVisible);
      DS.OpenEmpty;
      //
      while i <> total do
      begin
        continue := false;
        id := SLRec.Strings[i];
        ic := LByID(id);
        u := RByID(id);
        i := i + 1;
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////// Z B O Ž Í /////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        found := false;
        j := 0;
        while (not found) and (j <> SLBindsGoodsA.Count) do
        begin
          found := GetElemCount(AppServer.GetDBKeyValues(SourceName, rmPrimary, SLBindsGoodsA.Strings[j], Format('"ic_a" = %% AND "u_a" = %%', [ic, u])), ';') <> 0;
          j := j + 1;
        end;
        //
        j := 0;
        while (not found) and (j <> SLBindsGoodsB.Count) do
        begin
          found := GetElemCount(AppServer.GetDBKeyValues(SourceName, rmPrimary, SLBindsGoodsA.Strings[j], Format('"ic_b" = %% AND "u_b" = %%', [ic, u])), ';') <> 0;
          j := j + 1;
        end;
        //
        if not found then
        begin
          DS.Filter := Format('"ic_b" = %% AND "u_b" = %% AND "42056533,10.ic" is NULL AND "42056533,10.u" is NULL AND "42059021,10.ic" is NULL AND "42059021,10.u" is NULL', [ic, u]);
          found := not DS.IsEmpty;
        end;
        //
        if found then
        begin
          ////////////////////////////////////////////////////////////////////////////////////////////////////
          ///////////////////////////////////////////// R O L E //////////////////////////////////////////////
          ////////////////////////////////////////////////////////////////////////////////////////////////////
          found := false;
          j := 0;
          while (not found) and (j <> SLBindsRolesA.Count) do
          begin
            found := GetElemCount(AppServer.GetDBKeyValues(SourceName, rmPrimary, SLBindsRolesA.Strings[j], Format('"ic_a" = %% AND "u_a" = %%', [ic, u])), ';') <> 0;
            j := j + 1;
          end;
          //
          j := 0;
          while (not found) and (j <> SLBindsRolesA.Count) do
          begin
            found := GetElemCount(AppServer.GetDBKeyValues(SourceName, rmPrimary, SLBindsRolesB.Strings[j], Format('"ic_b" = %% AND "u_b" = %%', [ic, u])), ';') <> 0;
            j := j + 1;
          end;
          //
          DS.Filter := Format('"ic_b" = %% AND "u_b" = %% AND (("42056533,10.ic" is not NULL AND "42056533,10.u" is not NULL) OR ("42059021,10.ic" is not NULL AND "42059021,10.u" is not NULL))', [ic, u]);
          found := not DS.IsEmpty;
          //
          if not found then
            DeleteRecordFromClass(id, '3009,10', delete_binds_roles_A, delete_binds_roles_B);
          // else se neřeší - nemělo by nastat
        end else
          DeleteRecordFromClass(id, '3460,10', delete_binds_goods_A, delete_binds_goods_B);
      end;
    finally
      SLRec.Free;
      SLBindsGoodsA.Free;
      SLBindsGoodsB.Free;
      SLBindsRolesA.Free;
      SLBindsRolesB.Free;
      SLProblems.Free;
    end;
  end;
  // AV - end
  
begin
  // PeM - založení DT Převedení položek (SPUSTIT)
  if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '101,0', '42107567,10', ftID) then
  begin
    DSClass := TAppDataSet.Create;
    try
      DSClass.SetDSParams(SourceName, rmPrimary, '902,0', dsaFullNonVisible);
      DSClass.NoMacros := true;
      DSClass.OpenEmpty;
      DSClass.Append;
      DSClass.FieldByName('ic').AsString := '42107567';
      DSClass.FieldByName('u').AsString := '10';
      DSClass.FieldByName('ic_a').AsString := '29555';
      DSClass.FieldByName('u_a').AsString := '10';
      DSClass.FieldByName('ic_b').AsString := '29555';
      DSClass.FieldByName('u_b').AsString := '10';
      DSClass.FieldByName('611,0').AsString := 'Převedení položek';
      DSClass.FieldByName('2652,0').AsString := '0';
      DSClass.FieldByName('13265,0').AsString := '1';
      DSClass.FieldByName('615,0').AsString := '4';
      DSClass.FieldByName('613,0').AsString := '';
      DSClass.FieldByName('614,0').AsString := '';
      if DSClass.FindField('18361668,10') <> nil then
      begin
        DSClass.FieldByName('18361668,10').AsString := '';
        DSClass.FieldByName('18361669,10').AsString := '';
        DSClass.FieldByName('18361670,10').AsString := '';
      end;
      DSClass.PostNoConfirm;
    finally
      DSClass.Free;
    end;
  end;

  // SQL - nasypání ID z DT Převedení jedné položky do Převedení položek (SPUSTIT)
  AppServer.SetSQLScript(SourceName,TargetPath + 'Reinstall_1160BI1.sql'); // speciálně pro PeM

  // PeM - tvorba hierarchie (SPUSTIT)
  if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '136,0','42122013,10',ftID) then
  begin
    SLEx := TStringList.Create;
    try
      SLEx.Add('ic=42122013');
      SLEx.Add('u=10');
      SLEx.Add('ic_a=42107567');
      SLEx.Add('u_a=10');
      SLEx.Add('ic_b=209217');
      SLEx.Add('u_b=9');    
      AppServer.InsertDBRecord(SourceName,MainLang,'136,0',false,SLEx);  
    finally
      SLEx.Free;
    end;
  end;  
  
  // MP - doplnění hodnoty do povinného atributu "Akceptovat ve volnu a ve svátek"      -  NESPOUŠTĚT
  MP_SLDochSl := TStringList.Create;
  try
    StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '17830,10218', '"20357932,10" is null'), ';', MP_SLDochSl);
    while MP_SLDochSl.Count > MP_Index do
    begin
      AppServer.SetDBAtrValue(SourceName, '', '17830,10218', '20357932,10', MP_SLDochSl.Strings[MP_Index], '0');
      MP_Index := MP_Index + 1;
    end;
  finally
    MP_SLDochSl.Free;  
  end;
  // MP end  
  
  // ZS - vymaz dat DT 29901874,10 (NESPOUSTET)
  if (AppServer.GetDBAtrValue(SourceName, rmPrimary, '401,0', '101,0', '201,1', '29901874,10') = 'xONZ PPV') then
  begin
    SLID := TStringList.Create;
    try
      // vymaz dat DT 29901874,10
      StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '29901874,10', ''), ';', SLID);
      i := 0;
      while (i < SLID.Count) do
      begin
        AppServer.DeleteDBRecord(SourceName, '29901874,10', SLID.Strings[i], false);
          
        i := i + 1;  // dalsi zaznam
      end;
      i := 0;
    finally
      SLID.Free;
    end;
    
    transRep := true;
  end;
  // ZS konec
  
  // ZS priprava prepojeni DT 446925,10 a 452437,10 na DT 454280,10 (NESPOUSTET)
  if (AppServer.GetDBKeyValue(SourceName, rmPrimary, '101,0', '446925,10', ftID, ftIDA) = '150,0') then
  begin
    SLPpv := TStringList.Create;
    SLPar := TStringList.Create;
    SL := TStringList.Create;
    try
      // PPV
      StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '446925,10', ''), ';', SLPpv);
      i := 0;
      while (i < SLPpv.Count) do
      begin
        idEmpl := AppServer.GetDBKeyValue(SourceName, rmPrimary, '446925,10', SLPpv.Strings[i], ftID, ftIDA);
        if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '454280,10', idEmpl) then
        begin
          // neni zamestnanec, zarazeni do zamestnancu
          SL.Clear;
          SL.Add('ic='+LByID(idEmpl));
          SL.Add('u='+RByID(idEmpl));
          AppServer.InsertDBRecord(SourceName, MainLang, '454280,10', true, SL);
        end;
        
        i := i + 1;  // dalsi PPV
      end;
      SLPpv.Clear;
      
      // Osobni parametry
      StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '452437,10', ''), ';', SLPar);
      i := 0;
      while (i < SLPar.Count) do
      begin
        idEmpl := AppServer.GetDBKeyValue(SourceName, rmPrimary, '452437,10', SLPar.Strings[i], ftID, ftIDA);
        if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '454280,10', idEmpl) then
        begin
          // neni zamestnanec, zarazeni do zamestnancu
          SL.Clear;
          SL.Add('ic='+LByID(idEmpl));
          SL.Add('u='+RByID(idEmpl));
          AppServer.InsertDBRecord(SourceName, MainLang, '454280,10', true, SL);
        end;
        
        i := i + 1;  // dalsi PPV
      end;
    finally
      SLPpv.Free;
      SLPar.Free;
      SL.Free;
    end;
  end;
  // ZS konec
  
  AppServer.SetSQLScript(SourceName,TargetPath + 'Reinstall_1160BI.sql');
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  M17059359_10;  // NEMAZAT, STANDARDNI SOUCAST REINSTALACE
  AppServer.SetSQLScript(SourceName,TargetPath + 'Reinstall_1160AD.sql'); 
  
  
  //PŠtu - BEGIN       (NESPOUSTET)
  //10.6.2025 převzetí hodnoty do nového údaje: Nákup
  PStu_Set1Global('1176227,10', '42103547,10');
  //14.7.2025 OOP: plnit datum DPF, když je vazba 38346003,10 na položku SV
  PStu_naprav2720152;
  //PŠtu - END
  
  //VKo - BEGIN (SPOUŠTĚT)
  //Doplnění vazby sazby DPH na stát
  M40898706_10;
  //VKo - END
  
  // PeM - BEGIN - výchozí hodnota pro cenu požadavku na materiál (NESPOUSTET)
  PeM_IDKonf := GetUserGlobals('', 'ic', '')+','+GetUserGlobals('', 'u', '');
  if LByID(PeM_IDKonf) <> '' then
    AppServer.SetDBAtrValue(SourceName, MainLang, '15777,10', '42129657,10', PeM_IDKonf, '2');
  // PeM - END
    
  //MaSu - BEGIN - NESPOUSTET
  //Reinstall do údaje "Typ přesunu"
  MaSu_SL := TStringList.Create;
  try
    StringToSL(AppServer.GetDBKeyValues(SourceName,rmPrimary,'39894462,10','("42144175,10" is null)'),';',MaSu_SL);
    MaSu_i := 0;
    while MaSu_i < MaSu_SL.Count do
    begin
      AppServer.SetDBAtrValue(SourceName,'','39894462,10','42144175,10',MaSu_SL.Strings[MaSu_i],'0');
      MaSu_i := MaSu_i + 1;
    end;
  finally
    MaSu_SL.Free;
  end;
  //MaSu - END
  
  //MP nastavení doch. složek   - NESPOUŠTĚT
  if Legislation = '745998,10' then // CZ
  begin
    VeVolnuSouvNepr('215');
    VeVolnuSouvNepr('216');  
  end;
  if Legislation = '740878,10' then // SK
  begin
    VeVolnuSouvNepr('202');
    VeVolnuSouvNepr('203');
    VeVolnuSouvNepr('210'); 
    VeVolnuSouvNepr('211');
    VeVolnuSouvNepr('213');
    VeVolnuSouvNepr('214'); 
    VeVolnuSouvNepr('215');
    VeVolnuSouvNepr('216');
    VeVolnuSouvNepr('217'); 
    VeVolnuSouvNepr('218');
    VeVolnuSouvNepr('219');
    VeVolnuSouvNepr('232'); 
    VeVolnuSouvNepr('233');
    VeVolnuSouvNepr('251');
    VeVolnuSouvNepr('252'); 
    VeVolnuSouvNepr('253');
    VeVolnuSouvNepr('254');
    VeVolnuSouvNepr('255'); 
    VeVolnuSouvNepr('260');
    VeVolnuSouvNepr('261'); 
  end;  
  //MP end
  
  // AV1 - Přegenerování struktury pro přístupová práva - Nespoštět
  M29212145_10;
  // AV1 - end

  // KaSo - Nastavení hodnoty konfigurace obchodních partnerů (změna z bit na množina) --- Nespouštět
  if (AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '15777,10', '26698240,10', '15852,10') = '1') then // Globální konfigurace II, Neaktualizovat adresu z ARES = 1 - Ano
    AppServer.SetDBAtrValue(SourceName, '', '15777,10', '26698240,10', '15852,10', '15'); // nově množina 15 - [Partner, Pobočka, Dodací adresa, Korespondenční adresa] tj. všecno - Ano
  // KaSo - end
  
  //MaSu - BEGIN - SPUSTIT
  //Promázávání synchronizace v uživatelském komunikátoru
  MaSu_DS := TAppDataSet.Create;
  try
    MaSu_DS.SetDSParams(SourceName,rmPrimary,'42335828,10',dsaEditNonVisible);
    MaSu_DS.Filter := '("42335830,10.ic" is not null) and (("42335831,10" is not null) or ("42335832,10" is not null))';
    MaSu_DS.Open;
    while not MaSu_DS.EOF do
    begin
      MaSu_DS.Edit;
      MaSu_DS.FieldByName('42335831,10').AsString := '';
      MaSu_DS.FieldByName('42335832,10').AsString := '';
      MaSu_DS.PostNoConfirm;
      MaSu_DS.Next;
    end;
  finally
    MaSu_DS.Free;
  end;
  //MaSu - END
  
  // ZS prevazani mzdovych vykazu na zamestnance (NESPOUSTET)
  if transRep then
  begin
    SLID := TStringList.Create;
    SL := TStringList.Create;
    try
      // prevazani mzdovych vykazu na zamestnance
      SLID.Clear;
      StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '12644692,10', ''), ';', SLID);
      i := 0;
      while (i < SLID.Count) do
      begin
        idPpv := AppServer.GetDBKeyValue(SourceName, rmPrimary, '12644692,10', SLID.Strings[i], ftID, ftIDA);
        idMV := AppServer.GetDBKeyValue(SourceName, rmPrimary, '12644692,10', SLID.Strings[i], ftID, ftIDB);
        idEmpl := AppServer.GetDBKeyValue(SourceName, rmPrimary, '446925,10', idPpv, ftID, ftIDA);
        if AppServer.ExistDBKeyValue(SourceName, rmPrimary, '454280,10', idEmpl) then
        begin
          // jen pokud je zamestnanec
          // vazba zamestanace na mzdovy vykaz
          SL.Clear;
          SL.Add('ic_a='+LByID(idEmpl));
          SL.Add('u_a='+RByID(idEmpl));
          SL.Add('ic_b='+LByID(idMV));
          SL.Add('u_b='+RByID(idMV));
          AppServer.InsertDBRecord(SourceName, '', '29901874,10', false, SL);
          ic := SL.Values['ic'];
          u := SL.Values['u'];
          
          // vazba na PPV
          SL.Clear;
          SL.Add('ic_a='+LByID(idPpv));
          SL.Add('u_a='+RByID(idPpv));
          SL.Add('ic_b='+ic);
          SL.Add('u_b='+u);
          AppServer.InsertDBRecord(SourceName, '', '42404453,10', false, SL);
        end;
        
        i := i + 1;  // dalsi zaznam
      end;
    finally
      SLID.Free;
      SL.Free;
    end;
  end;
  // ZS konec
  
  // AV - Nepospuštět
  AV1_REINSTALL_ODDELENI_ROLI_A_ZBOZI;
  // AV
  
  //VKo - Nespouštět
  if AppServer.ExistDBKeyValue(SourceName, rmPrimary, '131,0', '6659249,10016') then
    AppServer.DeleteDBRecord(SourceName, '131,0', '6659249,10016', false);
  //VKo
  
  //VKo - Nespouštět
  ID := AppServer.GetDBLinkKeyValue(SourceName, rmPrimary, '141,0', '6299,10016', '6275168,10016');
  if (ID <> '') then
    if (GetElemCount(ID, ';') = 1) then
      AppServer.DeleteDBRecord(SourceName, '141,0', ID, false);
  //Vko
  
  // TB - nespoustet
  // Konverze výchozích druhů akce
  M42155592_10;
  // TB
  
  
  // Dingo - start - nespouštět
  dingo_sl := TStringList.Create;
  dingo_ds := TAppDataSet.Create;
  try
    // naplneni vazby "zdrojova polozka dokladu" pro polozky pripravnych davek
    dingo_ds.SetDSParams(SourceName, rmPrimary, '180610,11011', dsaReadNonVisible);
    dingo_ds.Filter := 'not "14439,11011:ao.139338,11011" in (8, 3, 5) and "180612,11011.ic" is null and "180612,11011.u" is null and "180687,11011.ic" is not null and "180687,11011.u" is not null';
    dingo_ds.NoMacros := True;
    dingo_ds.Open;
    
    // tvorba vazby: obchodni partner v davce
    while not dingo_ds.EOF do
      begin
        dingo_sl.Clear;
        dingo_sl.Values['ic_a'] := dingo_ds.FieldByName('ic').AsString;
        dingo_sl.Values['u_a'] := dingo_ds.FieldByName('u').AsString;
        dingo_sl.Values['ic_b'] := dingo_ds.FieldByName('180700,11011.ic_b').AsString;
        dingo_sl.Values['u_b'] := dingo_ds.FieldByName('180700,11011.u_b').AsString;
        AppServer.InsertDBRecord(SourceName, '', '139552,11011', False, dingo_sl);
        
        //
        dingo_ds.Next;
      end;
    
    // nacteni: blokovave skladove pozice
    dingo_ds.Close;
    dingo_ds.SetDSParams(SourceName, rmPrimary, '179585,11011', dsaReadNonVisible);
    dingo_ds.Filter := '"530200,11011.ic" is null and "530200,11011.u" is null';
    dingo_ds.NoMacros := True;
    dingo_ds.Open;
    
    // tvorba vazby: zdrojova davka blokovane pozice
    while not dingo_ds.EOF do
      begin
        dingo_sSourceBatchID := AppServer.GetDBKeyValue(SourceName, rmPrimary, '179057,11011', dingo_ds.GetKeyValue('', ftIDA), ftIDA, ftIDB);
        if dingo_sSourceBatchID <> '' then
          begin
            dingo_sl.Clear;
            dingo_sl.Values['ic_a'] := dingo_ds.FieldByName('ic').AsString;
            dingo_sl.Values['u_a'] := dingo_ds.FieldByName('u').AsString;
            dingo_sl.Values['ic_b'] := LByID(dingo_sSourceBatchID);
            dingo_sl.Values['u_b'] := RByID(dingo_sSourceBatchID);
            AppServer.InsertDBRecord(SourceName, '', '530198,11011', False, dingo_sl);
            
          end;
        
        //
        dingo_ds.Next;
      end;
    
    // nacteni: blokovave manipulacni jednotky
    dingo_ds.Close;
    dingo_ds.SetDSParams(SourceName, rmPrimary, '426992,11011', dsaReadNonVisible);
    dingo_ds.Filter := '"530202,11011.ic" is null and "530202,11011.u" is null';
    dingo_ds.NoMacros := True;
    dingo_ds.Open;
    
    // tvorba vazby: zdrojova davka blokovane manipulacni jednotky
    while not dingo_ds.EOF do
      begin
        dingo_sSourceBatchID := AppServer.GetDBKeyValue(SourceName, rmPrimary, '179057,11011', dingo_ds.GetKeyValue('', ftIDA), ftIDA, ftIDB);
        if dingo_sSourceBatchID <> '' then
          begin
            dingo_sl.Clear;
            dingo_sl.Values['ic_a'] := dingo_ds.FieldByName('ic').AsString;
            dingo_sl.Values['u_a'] := dingo_ds.FieldByName('u').AsString;
            dingo_sl.Values['ic_b'] := LByID(dingo_sSourceBatchID);
            dingo_sl.Values['u_b'] := RByID(dingo_sSourceBatchID);
            AppServer.InsertDBRecord(SourceName, '', '530199,11011', False, dingo_sl);
            
          end;
        
        //
        dingo_ds.Next;
      end;
    
  finally
    dingo_ds.Free;
    dingo_sl.Free;
  end;

  // Dingo - end
  
  
  
  
  
end.